﻿using Avalonia.Controls;
using Avalonia.Interactivity;
using DevHub.WindowsApp.ViewModels.Pages.Help;

namespace DevHub.WindowsApp.Dialogs;

public partial class FontIconDialog : UserControl
{
    public FontIconDialog(FontIconInfo iconInfo)
    {
        InitializeComponent();
        FontIcon.Glyph = iconInfo.Glyph;
        Block.Text = iconInfo.Codepoint;
        XamlCodeBlock.Text = iconInfo.XamlGlyph;
        CSCodeBlock.Text = iconInfo.CSharpGlyph;
    }

    private void NameCopyClick(object? sender, RoutedEventArgs e)
    {
        if (string.IsNullOrEmpty(Block.Text)) return;
        var top = TopLevel.GetTopLevel(this);
        top?.Clipboard?.SetTextAsync(Block.Text);
    }

    private void XamlCopyClick(object? sender, RoutedEventArgs e)
    {
        if (string.IsNullOrEmpty(XamlCodeBlock.Text)) return;
        var top = TopLevel.GetTopLevel(this);
        top?.Clipboard?.SetTextAsync(XamlCodeBlock.Text);
    }

    private void CsharpCopyClick(object? sender, RoutedEventArgs e)
    {
        if (string.IsNullOrEmpty(CSCodeBlock.Text)) return;
        var top = TopLevel.GetTopLevel(this);
        top?.Clipboard?.SetTextAsync(CSCodeBlock.Text);
    }
}